package com.qf.lanzhou.shop.api.service.impl;

import com.qf.lanzhou.shop.pojo.entity.Goods;
import com.qf.lanzhou.shop.pojo.entity.GoodsUrl;
import com.qf.lanzhou.shop.api.dao.GoodsMapper;
import com.qf.lanzhou.shop.api.service.GoodsService;
import com.qf.lanzhou.shop.pojo.qo.GoodsSizeQo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Random;

/**
 * @author LEON-HE
 */
@Service
public class GoodsServiceImpl implements GoodsService {
    @Autowired
    private GoodsMapper goodsMapper;

    @Override
    public Goods getGoodsById(Long goodsId) {
        Goods goods = goodsMapper.selectGoodByGoodsById(goodsId);
        List<GoodsSizeQo> goodsSizeQos = goodsMapper.selectSizeByBarCode(goods.getBarCode());
        goods.setGoodsSizeQoList(goodsSizeQos);
        return goods;
    }

    @Override
    public List<GoodsUrl> getGoodsUrlById(Long goodsId) {
        List<GoodsUrl> goodsUrls = goodsMapper.selectGoodsUrlById(goodsId);
        return goodsUrls;
    }

    @Override
    public List<Goods> getGoodsList() {
        List<Goods> goodsForIndex = goodsMapper.selectGoodsForIndex();
        return goodsForIndex;
    }

    @Override
    public Goods getSnapUpGoods() {
        List<Goods> goods = goodsMapper.selectSnapUpGoods();
        Random random = new Random();
        int randomNum = random.nextInt(goods.size());
        return goods.get(randomNum);
    }

    @Override
    public List<Goods> getBestSellingGoods() {
        List<Goods> goods = goodsMapper.selectBestSellingGoods();
        return goods;
    }

    @Override
    public List<Goods> getDiscountGoods() {
        List<Goods> goods = goodsMapper.selectDiscountGoods();
        return goods;
    }
}
